import Taro, {Component} from '@tarojs/taro'
import {connect} from '@tarojs/redux'
import {View} from '@tarojs/components'
import './index.less'
import _pickBy from 'lodash/pickBy'
import _startsWith from 'lodash/startsWith'
import {AtButton, AtIcon} from "taro-ui";

@connect(({environmentAssessment, loading}) => ({
  environmentAssessment,
  loading: _pickBy(loading.effects, (value, key) => {
    return _startsWith(key, 'environmentAssessment')
  })
}))


export default class environment extends Component {

  config = {
    navigationBarTitleText: ''
  }

  componentWillMount() {
  }

  componentDidMount() {
    const {dispatch} = this.props;
    dispatch({type: 'environmentAssessment/loadHasView'})
  }

  componentWillUnmount() {
  }

  componentDidShow() {
  }

  componentDidHide() {
  }

  onShareAppMessage(options) {

    const {dispatch} = this.props;
    dispatch({type: 'environmentAssessment/addView'})

    // 设置菜单中的转发按钮触发转发事件时的转发内容
    return {
      title: "江苏厂管家环评办理",        // 默认是小程序的名称(可以写slogan等)
      path: `pages/environmentAssessment/index`,        // 默认是当前页面，必须是以‘/’开头的完整路径
    };
  }

  phoneCall(num, e) {
    Taro.makePhoneCall({phoneNumber: num})
    //阻止事件向上级冒泡
    e.stopPropagation();
  }

  render() {
    const {
      environmentAssessment
    } = this.props;
    let {showCellphone,cellphone} = environmentAssessment
    return (
      <View className='index'>
        <image mode='widthFix' src="https://factory.wenyangchou.com/myfiles/system/huanping.jpg"/>

        {showCellphone?<View className='shareBtn'>
          <AtButton circle onClick={this.phoneCall.bind(this, cellphone || '13966110110')}>
            <AtIcon value='phone' color='#fff' size='18' ></AtIcon>
            <View className='tabBarText'>&ensp;&ensp;拨打电话</View>
          </AtButton>
        </View>:<View className='shareBtn'>
          <AtButton circle openType='share'>
            <AtIcon value='external-link' color='#fff' size='18'></AtIcon>
            <View className='tabBarText'>&ensp;&ensp;分享解锁电话</View>
          </AtButton>
        </View>}
      </View>
    )
  }
}
